package icu.qx.pbs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.common.constant.TableNameEnum;
import icu.qx.common.utils.CodeUtils;
import icu.qx.pbs.domain.PbsProcedure;
import icu.qx.pbs.mapper.PbsProcedureMapper;
import icu.qx.pbs.service.IPbsProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 工序Service业务层处理
 *
 * @author yong
 * @date 2024-06-15
 */
@Service
public class PbsProcedureServiceImpl implements IPbsProcedureService {
    @Autowired
    private PbsProcedureMapper pbsProcedureMapper;

    @Autowired
    private CodeUtils codeUtils;

    /**
     * 查询工序
     *
     * @param procedureCode 工序主键
     * @return 工序
     */
    @Override
    public PbsProcedure selectPbsProcedureByProcedureCode(String procedureCode) {
        return pbsProcedureMapper.selectPbsProcedureByProcedureCode(procedureCode);
    }

    /**
     * 查询工序列表
     *
     * @param pbsProcedure 工序
     * @return 工序
     */
    @Override
    public List<PbsProcedure> selectPbsProcedureList(PbsProcedure pbsProcedure) {
        return pbsProcedureMapper.selectPbsProcedureList(pbsProcedure);
    }

    /**
     * 新增工序
     *
     * @param pbsProcedure 工序
     * @return 结果
     */
    @Override
    public int insertPbsProcedure(PbsProcedure pbsProcedure) {
        String procedureCode = codeUtils.generateCode(TableNameEnum.PBS_PROCEDURE.getTableName());
        pbsProcedure.setProcedureCode(procedureCode);
        pbsProcedure.setCreateBy(SecurityUtils.getUsername());
        pbsProcedure.setCreateTime(DateUtils.getNowDate());
        return pbsProcedureMapper.insertPbsProcedure(pbsProcedure);
    }

    /**
     * 修改工序
     *
     * @param pbsProcedure 工序
     * @return 结果
     */
    @Override
    public int updatePbsProcedure(PbsProcedure pbsProcedure) {
        pbsProcedure.setCreateBy(SecurityUtils.getUsername());
        pbsProcedure.setUpdateTime(DateUtils.getNowDate());
        return pbsProcedureMapper.updatePbsProcedure(pbsProcedure);
    }

    /**
     * 批量删除工序
     *
     * @param procedureCodes 需要删除的工序主键
     * @return 结果
     */
    @Override
    public int deletePbsProcedureByProcedureCodes(String[] procedureCodes) {
        return pbsProcedureMapper.deletePbsProcedureByProcedureCodes(procedureCodes);
    }

    /**
     * 删除工序信息
     *
     * @param procedureCode 工序主键
     * @return 结果
     */
    @Override
    public int deletePbsProcedureByProcedureCode(String procedureCode) {
        return pbsProcedureMapper.deletePbsProcedureByProcedureCode(procedureCode);
    }
}
